rdkafka-dotnet - C# Apache Kafka client

rdkafka-dotnet is a C# client for Apache Kafka based on librdkafka.


Just reference the RdKafka NuGet package

Api Reference

Read the Api Documentation here


Producing messages

using (Producer producer = new Producer(""))
using (Topic topic = producer.Topic("testtopic"))
    byte[] data = Encoding.UTF8.GetBytes("Hello RdKafka");
    DeliveryReport deliveryReport = await topic.Produce(data);
    Console.WriteLine($"Produced to Partition: {deliveryReport.Partition}, Offset: {deliveryReport.Offset}");

Consuming messages

var config = new Config() { GroupId = "example-csharp-consumer" };
using (var consumer = new EventConsumer(config, ""))
    consumer.OnMessage += (obj, msg) =>
        string text = Encoding.UTF8.GetString(msg.Payload, 0, msg.Payload.Length);
        Console.WriteLine($"Topic: {msg.Topic} Partition: {msg.Partition} Offset: {msg.Offset} {text}");

    consumer.Subscribe(new []{"testtopic"});

    Console.WriteLine("Started consumer, press enter to stop consuming");